home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / hello / hello.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.7 KB  |  176 lines

  1. // hello.cpp : Defines the class behaviors for the application.
  2. //           Hello is a simple program which consists of a main window
  3. //           and an "About" dialog which can be invoked by a menu choice.
  4. //           It is intended to serve as a starting-point for new
  5. //           applications.
  6. //
  7. // This is a part of the Microsoft Foundation Classes C++ library.
  8. // Copyright (C) 1999 Microsoft Corporation
  9. // All rights reserved.
  10. //
  11. // This source code is only intended as a supplement to the
  12. // Microsoft Foundation Classes Reference and related
  13. // electronic documentation provided with the library.
  14. // See these sources for detailed information regarding the
  15. // Microsoft Foundation Classes product.
  16.  
  17. #include "stdafx.h"
  18. #include "resource.h"
  19.  
  20. #include "hello.h"
  21. /////////////////////////////////////////////////////////////////////////////
  22.  
  23. // theApp:
  24. // This code runs the application automatically
  25. //
  26. CTheApp helloApp;
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29.  
  30. // CMainWindow constructor:
  31. // Load the application frame window
  32. //
  33. CMainWindow::CMainWindow()
  34. {
  35.     LoadFrame(IDR_MAINFRAME);
  36.  
  37.     // For MFCCE 2.0 and earlier, a command bar was created during
  38.     // the CFrameWnd creation. For MFCCE 2.01 and later, a command bar 
  39.     // is automatically created for you during the call to AddAdornments().
  40.     AddAdornments(0);
  41. }
  42.  
  43. // OnPaint:
  44. // Function called whenever WCE sends the message WM_PAINT
  45. // This routine draws the string "Hello, WCE!", loaded from IDS_STRING,
  46. // in the center of the application window.
  47. //
  48. void CMainWindow::OnPaint()
  49. {
  50.     CRect rect;
  51.     CString s;
  52.     GetClientRect(rect);
  53.  
  54.     CPaintDC dc(this);
  55.     dc.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
  56.     dc.SetBkMode(TRANSPARENT);
  57.     s.LoadString(IDS_HELLO);
  58.     dc.DrawText(s, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  59. }
  60.  
  61. // CMainWindow message map:
  62. // Associate messages with member functions.
  63. //
  64. // It is implied that the ON_WM_PAINT macro expects a member function
  65. // "void OnPaint()".
  66. //
  67. // It is implied that members connected with the ON_COMMAND macro
  68. // receive no arguments and are void of return type, e.g., "void OnAbout()".
  69. //
  70. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  71.     //{{AFX_MSG_MAP( CMainWindow )
  72.     ON_WM_PAINT()
  73.     ON_COMMAND(ID_APP_ABOUT, OnAbout)
  74.     //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CTheApp
  79.  
  80. // InitInstance:
  81. // When any CTheApp object is created, this member function is automatically
  82. // called.  Any data may be set up at this point.
  83. //
  84. // Also, the main window of the application should be created and shown here.
  85. // Return TRUE if the initialization is successful.
  86. //
  87. BOOL CTheApp::InitInstance()
  88. {
  89.     TRACE0("CTheApp::InitInstance\n");
  90.     m_pMainWnd = new CMainWindow;
  91.     m_pMainWnd->ShowWindow(m_nCmdShow);
  92.     m_pMainWnd->UpdateWindow();
  93.  
  94.     return TRUE;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CAboutDlg dialog
  98.  
  99. class CAboutDlg : public CDialog
  100. {
  101. // Construction
  102. public:
  103.     CAboutDlg(CWnd* pParent = NULL);   // standard constructor
  104.  
  105. // Dialog Data
  106.     //{{AFX_DATA(CAboutDlg)
  107.     enum { IDD = IDD_ABOUTBOX };
  108.     //}}AFX_DATA
  109.  
  110.  
  111. // Overrides
  112.     // ClassWizard generated virtual function overrides
  113.     //{{AFX_VIRTUAL(CAboutDlg)
  114.     protected:
  115.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  116.     //}}AFX_VIRTUAL
  117.  
  118. // Implementation
  119. protected:
  120.  
  121.     // Generated message map functions
  122.     //{{AFX_MSG(CAboutDlg)
  123.     virtual BOOL OnInitDialog();
  124.     //}}AFX_MSG
  125.     DECLARE_MESSAGE_MAP()
  126. };
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CAboutDlg dialog
  129.  
  130.  
  131. CAboutDlg::CAboutDlg(CWnd* pParent /*=NULL*/)
  132.     : CDialog(CAboutDlg::IDD, pParent)
  133. {
  134.     //{{AFX_DATA_INIT(CAboutDlg)
  135.     //}}AFX_DATA_INIT
  136. }
  137.  
  138.  
  139. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  140. {
  141.     CDialog::DoDataExchange(pDX);
  142.     //{{AFX_DATA_MAP(CAboutDlg)
  143.     //}}AFX_DATA_MAP
  144. }
  145.  
  146.  
  147. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  148.     //{{AFX_MSG_MAP(CAboutDlg)
  149.     //}}AFX_MSG_MAP
  150. END_MESSAGE_MAP()
  151.  
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CAboutDlg message handlers
  154.  
  155. BOOL CAboutDlg::OnInitDialog() 
  156. {
  157.     CDialog::OnInitDialog();
  158.     CenterWindow();    
  159.     return TRUE;  // return TRUE unless you set the focus to a control
  160.                   // EXCEPTION: OCX Property Pages should return FALSE
  161. }
  162.  
  163. // OnAbout:
  164. // Function called when the message WM_COMMAND, with an
  165. // ID_APP_ABOUT code, is received by the CMainWindow class object.
  166. // The message map below is responsible for this routing.
  167. //
  168. // We create a CDialog object using the "AboutBox" resource ,
  169. // defined in hello.rc, and invoke it.
  170. //
  171. void CMainWindow::OnAbout()
  172. {
  173.     CAboutDlg about;
  174.     about.DoModal();
  175. }
  176.